
work_book = 'hello'
work_book += 'hello'
work_book += 'hello'

def  say():
    print("Hello")

say()

work_book += 'hello'


'''
摘自 JavaScript高级程序设计.pdf 40页
(1) 求这个数值绝对值的二进制码（例如，要求18 的二进制补码，先求18 的二进制码）；
(2) 求二进制反码，即将0 替换为1，将1 替换为0；
(3) 得到的二进制反码加1。
要根据这3 个步骤求得18 的二进制码，首先就要求得18 的二进制码，即：
0000 0000 0000 0000 0000 0000 0001 0010
然后，求其二进制反码，即0 和1 互换：
1111 1111 1111 1111 1111 1111 1110 1101
最后，二进制反码加1：
1111 1111 1111 1111 1111 1111 1110 1101
1
---------------------------------------
1111 1111 1111 1111 1111 1111 1110 1110
这样，就求得了18 的二进制表示，即11111111111111111111111111101110。要注意的是，在处理有
符号整数时，是不能访问位31 的。

附python进制转换函数：
使用Python内置函数：bin()、oct()、int()、hex()可实现进制转换。

//该错误还没解决
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 0: invalid start byte 

'''

import urllib
import struct
import base64
from urllib import request
import bit_operator
import re

num = 26
num1 = ~num
print(num1,num<<1,bin(num))

bitNum = 1<<2 #1向高位移(左移)2位
ret = num & bitNum


print('ret',ret,int(0x7e),struct.calcsize('s'),hex(129),hex(130))

data = b'_\x14 \x8cAV/\xffyP&\xc9b\x13\x0e\xc0\x7fV#\xd87'
offset = 0
dl = struct.unpack_from('21s',data,offset);

print("dl",dl[0])

z = b'61736467'
print(z.decode('utf8'))

n = bytes(2) #232,3

print('n=',n)

byte = bytes()
h = hex(232)
print(h)
byte += bytes.fromhex(h[2:])
h = hex(3)
print("h=",h,h[2:])
h = h[2:]
if len(h)==1:h='0'+h 
byte += bytes.fromhex(h)

print(byte,len(byte),struct.unpack('h',byte),int(0xe8))

toc = {
    '1007':'100'
}
toc1 = {
    '1008':200
}
toc2 = {
    '1009':300
}
to = dict(toc,**toc1,**toc2) #合并两个字典
print(toc,type(toc),to,4%4)

def testF(a,b,c):
    print('testF=',a,b,c)

testF(*[1,2,3])

class Message(object):
   
    def __setitem__(self,k,v):
        print(k,v)
        self.__dict__[k] = v
    def update(self):
        key = 'msg'
        self[key] = 'hello'

m = Message()
m.update()
print(m,m.__class__.__name__)

t = (1,2,3)
s = {1,2,3}
d = {'age':20,'name':'kf'}
a = [1,2,3,4,5]
print(t,s,type(t),type(s),type(d),type(a),int(0x80),bin(128))

n = 16
print('n',n,bin(n),n>>2,int(0b10011001),int(0b100110),153>>2)
'''
print(bit_operator.check_bit2(153,0))
print(bit_operator.check_bit2(153,1))
print(bit_operator.check_bit2(153,2))
print(bit_operator.check_bit2(153,3))
print(bit_operator.check_bit2(153,4))
print("-----左移判断----")
print(bit_operator.check_bit(153,0))
print(bit_operator.check_bit(153,1))
print(bit_operator.check_bit(153,2))
print(bit_operator.check_bit(153,3))
print(bit_operator.check_bit(153,4))
'''

s = "GET /user/%5c%123 HTTP/1.1 \
Accept-Encoding: gzip, deflate \
Host: 127.0.0.1:5000 \
Accept: */* \
Connection: close\
Referer: http://127.0.0.1:5000/user/"

reObj = re.compile(r'/user/\S*')

ret = reObj.search(s)
print(ret)
name = "test"
path=r'z:\auto\{0}\new.sh'.format(name)
print(path)

from enum import Enum

class Etype(Enum):
    image = 0
    Button = 1
    text = 2
    richtext = 3
    loader = 4

import math

fileds = ['code','name','level','desc']
print("排序前 fileds",fileds)
fileds.sort()
print("排序后 fileds",fileds)
obj = {'code':1001,'name':"kfz",'level':120}



def objToArr(obj):
    retArr = []    
    posNum = 1
    for i in range(len(fileds)):
        key = fileds[i]        
        if key in obj:     
            f = (1 << i)           
            posNum = posNum | f
            retArr.append(obj[key])
    retArr.insert(0,posNum)
    return retArr 

def arrToObj(arr):
    objRet = {}
    posNum = arr[0]
    startIdx = 1
    for i in range(len(fileds)):        
        pos = 1<<i
        ret = posNum & pos 
        print("pos",pos,"i",i,"ret",ret)
        if ret > 0:
            objRet[fileds[i]] = arr[startIdx]
            startIdx+=1
    print("arrToObj objRet",objRet)
    return objRet
    

retArr = objToArr(obj)
retObj = arrToObj(retArr)
print(2**4,1<<4,retArr)